<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>projectAndMachinesRelationsPage</title>
    <style>
    table{border-collapse:collapse;border-spacing:0;border-left:1px solid #888;border-top:1px solid #888;margin: auto}
    th,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}
    th{font-weight:bold;}
    body{text-align: center}
    </style>
    {% load static %}
    <script type='text/javascript' src="/static/js/jquery.min.js"></script>
    <script type='text/javascript' src="/static/js/user.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("input[name='getMachine']").click(function(){
                var pn = prompt("请输入NB的PN！");
                if(pn == null){
                    return false;
                }
                if(pn == ''){
                    alert('请输入NB的PN');
                    return false;
                }
                var projectId = $("#projectId").val();
                var stage = $("select[name='stage']").val();
                var machineId = $(this).parent().find("input[name='machineId']").val();
                var csrf = $("input[name='csrfmiddlewaretoken']").val();
                $.ajax({
                    url:'/getMachineToTestAndPn/',
                    type:'POST',
                    data:{pn:pn,projectId:projectId,machineId:machineId,stage:stage,csrfmiddlewaretoken:csrf},
                    success:function(data){
                        if(data=='1'){
                            alert('获取成功');
                            window.open('/projectAndMachinesRelationsPage/?projectId='+projectId+'&stage='+stage,'_self')
                        }else{
                            alert('获取失败');
                            window.location.reload();
                        }
                    }
                });
            });
            $("select[name='stage']").change(function(){
                var stage = $(this).val();
                var projectId = $("#projectId").val();
                window.open('/projectAndMachinesRelationsPage/?projectId='+projectId+'&stage='+stage,'_self')
            });
            $("select[name='projectId']").change(function(){
                var stage = $("#stage").val();
                var projectId = $(this).val();
                window.open('/projectAndMachinesRelationsPage/?projectId='+projectId+'&stage='+stage,'_self')
            });
        });
    </script>
</head>
<body>
    <table>
        <tr>
            <td>
                <select name="projectId">
                    {% for project in projects %}
                    <option value='{{ project.id }}' {% if project.id == projectSelect %}selected{% endif %}>{{ project.projectName }}</option>
                    {% endfor %}
                </select>
            </td>
            <td>
                <select name="stage">
                    <option value="1" {% if stage == '1' %}selected{% endif %}>SIT</option>
                    <option value="2" {% if stage == '2' %}selected{% endif %}>SVT</option>
                </select>
            </td>
        </tr>
    </table><br>
    <table>
        <tr>
            <td>笔电</td>
            <td>信息</td>
            <td>测试人</td>
        </tr>
        {% for machine in machineAndStatus %}
        <tr style="background-color: {% if machine.status == 0 %}red{% else %}green{% endif %};font-size: 12px;text-align: left">
            <td>{{ machine.machine.name }}</td>
            <td>{{ machine.machine.mainInfo }}</td>
            <td>{% if machine.status == 0 %}
                <input type="button" value="我来测" name="getMachine"/>
                <input type="hidden" name="machineId" value="{{  machine.machine.id }}"/>
                {% else %}
                    {{ machine.tester }}
                {% endif %}</td>
        </tr>
        {% endfor %}
    </table>
<input type="hidden" id="projectId" value="{{ projectSelect }}"/>
<input type="hidden" id="stage" value="{{ stage }}"/>
{% csrf_token %}
</body>
</html>